/**
 * plupload插件的封装，依赖于plupload.js
 */
function extPlupload(webPath,btn,obj) {
	btn = btn?btn:"pickfiles";
	var setting = {
		runtimes : 'html5,flash,silverlight,html4',
		browse_button : btn, // you can pass in id...
		url : webPath + '/intfc/upload.jhtml',
		flash_swf_url : webPath + '/plugin/plupload/Moxie.swf',
		silverlight_xap_url : webPath + '/plugin/plupload/Moxie.xap',
		unique_names : true,
		multi_selection : false,
		max_file_size : '2mb',
		chunk_size : '100kb',
		filters : [ 
		    {title : "image files",extensions : "jpg,jpeg,gif,png,bmp"}
		],

		init : {
			
			//调用init方法后调用
			PostInit : function() {
				$("#"+btn+"_pre").hide();
				$("#"+btn).show();
			},
			//选择文件后调用
			FilesAdded : function(up, files) {
				plupload.each(files, function(file) {
					$("#"+btn).after("<span id='pro_" + com.project.common.web.utils.id + "' class='procgressBar'/>");
					$("#"+btn).remove();
					$("#pro_" + com.project.common.web.utils.id).progressBar({boxImage:webPath+"/plugin/progressbar/images/progressbar.gif",barImage:webPath+"/plugin/progressbar/images/progressbg_green.gif"});
				});
				uploader.start();
			},

			//上传进度条
			UploadProgress : function(up, file) {
				$("#pro_" + com.project.common.web.utils.id).progressBar(file.percent);
			},
			//某个文件开始上传
			UploadFile : function(up, file) {

			},
			//某个文件上传完成
			FileUploaded : function(up, file, data) {
				if (data) {
					if (data.response) {
						var res = $.parseJSON(data.response);
						if (res && res.result == "success") {
							// $("#href").val(file.id+".mp4");
							// alert(file.id+"---"+file.name);
							$("#fileName").val(file.target_name);
						} else {
							alert("文件上传失败!");
						}
					} else {
						alert("文件上传失败!");
					}
				}
			},
			//所有图片上传完成
			UploadComplete : function(up, files) {
				
			},
			//发生错误
			Error : function(up, err) {
				var i = {
					e100 : '出现通用错误。',
					e200 : '出现Http错误。',
					e300 : '出现IO错误。',
					e500 : '出现控件初始化错误。',
					e600 : '文件大小不能超过2MB!',
					e601 : '只能选择mp4格式的文件!',
					e602 : '只能选择mp4格式的文件!',
					e700 : '只能选择mp4格式的文件!'
				};
				if (i['e' + (0 - err.code)]) {
					alert(i['e' + (0 - err.code)]);
				} else {
					alert("出现错误!");
				}
			}
		}
	};
	
	obj = $.extend(obj,setting);

	var uploader = new plupload.Uploader(obj);

	uploader.init();
	return uploader;
}